package com.gxa.controller;

import com.gxa.pojo.BulkGroup;
import com.gxa.pojo.Goods;
import com.gxa.pojo.Ludr;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: hw
 * Date: 2020/11/26 21:32
 * Description:
 * Version: V1.0
 */
@RestController
@RequestMapping("/ldur")
@Api(value = "幸运抽奖管理",tags = "幸运抽奖管理API")
public class LudrController {

    @Autowired(required = false)
    private ResponseData responseData;

    @RequestMapping(value = "/queryLudr",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "查询幸运抽奖信息",notes = "查询幸运抽奖信息",httpMethod = "GET")
    public ResponseData queryLudr()   {
        Ludr ludr = new Ludr();
        Goods goods = new Goods();

        ludr.setLudrStatu(1);
        ludr.setLudrHr(2);
        try {
            ludr.setLudrStart(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-11-11 08:50:12"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        try {
            ludr.setLudrLast(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-11-12 08:50:12"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        goods.setGoodsName("旺旺雪饼");
        ludr.setGoods(goods);

        if (responseData != null){
            responseData.setCode(200);
            responseData.setMsg("查询成功");
            responseData.setData(ludr);
        }else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");

        }
        return responseData;
    }

    @RequestMapping(value = "/queryLudrById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID查询幸运抽奖信息",notes = "根据ID查询幸运抽奖信息",httpMethod = "GET")
    public ResponseData queryLudrById(Integer ludrId){
        Ludr ludr = new Ludr();
        Goods goods = new Goods();

        ludr.setLudrStatu(2);
        ludr.setLudrHr(1);
        try {
            ludr.setLudrStart(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-11-11 08:50:12"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        try {
            ludr.setLudrLast(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-11-12 08:50:12"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        goods.setGoodsName("旺旺雪饼");
        ludr.setGoods(goods);

        if (responseData != null){
            responseData.setCode(200);
            responseData.setMsg("查询成功");
            responseData.setData(ludr);
        }else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");

        }
        return responseData;
    }

    @RequestMapping(value = "/addLudr",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "添加幸运抽奖信息",notes = "添加幸运抽奖信息",httpMethod = "POST")
    public ResponseData addLudr(Ludr ludr){

        if (ludr != null){
            responseData.setCode(200);
            responseData.setMsg("添加成功");
            responseData.setData(ludr);
        }else {
            responseData.setCode(500);
            responseData.setMsg("添加失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/updateLudrById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID修改幸运抽奖信息",notes = "根据ID修改幸运抽奖信息",httpMethod = "POST")
    public ResponseData updateLudrById(Integer ludrId){

        if (ludrId > 0){
            responseData.setCode(200);
            responseData.setMsg("修改成功");
//            responseData.setData(ludr);
        }else {
            responseData.setCode(500);
            responseData.setMsg("修改失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/delLudrById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID删除幸运抽奖信息",notes = "根据ID删除幸运抽奖信息",httpMethod = "POST")
    public ResponseData delLudrById(Integer ludrId){

        if (ludrId > 0){
            responseData.setCode(200);
            responseData.setMsg("删除成功");
//            responseData.setData(ludr);
        }else {
            responseData.setCode(500);
            responseData.setMsg("删除失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/queryBulkGroup",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "查询团购信息",notes = "查询团购信息",httpMethod = "GET")
    public ResponseData queryBulkGroup(){
        BulkGroup bulkGroup = new BulkGroup();

        bulkGroup.setBulkOid("2017081157525010");
        bulkGroup.setBulkLider("张三丰");
        bulkGroup.setGroupPnum(14);
        try {
            bulkGroup.setBulkBtime(new SimpleDateFormat("MM-dd HH:mm:ss").parse("07-11 15:21"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        try {
            bulkGroup.setBulkEtime(new SimpleDateFormat("MM-dd HH:mm:ss").parse("07-12 16:00"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        bulkGroup.setBulkStatus(2);
        if (bulkGroup != null){
            responseData.setCode(200);
            responseData.setMsg("查询成功");
            responseData.setData(bulkGroup);
        }else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");
        }
        return  responseData;
    }

    @RequestMapping(value = "/queryBulkGroupById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID查询团购信息",notes = "根据ID查询团购信息",httpMethod = "GET")
    public ResponseData queryBulkGroupById(Integer bulkGroupId){
        if (bulkGroupId > 0) {
            BulkGroup bulkGroup = new BulkGroup();

            bulkGroup.setBulkOid("2017081157525010");
            bulkGroup.setBulkLider("张四丰");
            bulkGroup.setGroupPnum(14);
            try {
                bulkGroup.setBulkBtime(new SimpleDateFormat("MM-dd HH:mm:ss").parse("08-11 15:21:21"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            try {
                bulkGroup.setBulkEtime(new SimpleDateFormat("MM-dd HH:mm:ss").parse("07-12 16:00:11"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            bulkGroup.setBulkStatus(2);
            if (bulkGroup != null) {
                responseData.setCode(200);
                responseData.setMsg("查询成功");
                responseData.setData(bulkGroup);
            } else {
                responseData.setCode(500);
                responseData.setMsg("查询失败");
            }
        }else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");
        }
        return  responseData;
    }


    @RequestMapping(value = "/queryWinerById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID查询中奖信息",notes = "根据ID查询中奖信息",httpMethod = "GET")
    public ResponseData queryWinerById(Integer winuser_id){
        if (winuser_id > 0) {
            Map map = new HashMap();
            map.put("orderId", 21);
            map.put("memberId", 16);
            map.put("memberNn", "不知道先森");
            map.put("memberPhone", "13438778422");
            if (map != null){
                responseData.setCode(200);
                responseData.setMsg("查询成功");
                responseData.setData(map);
            }else {
                responseData.setCode(500);
                responseData.setMsg("查询失败");
            }
        }else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/queryDefaultWiningBymemberId",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "查询参与抽奖用户信息",notes = "查询参与抽奖用户信息",httpMethod = "GET")
    public ResponseData queryDefaultWiningBymemberId(){
        Map map = new HashMap();
        map.put("memberId",12);
        map.put("orderId",30);
        map.put("memberNn","喜羊羊");
        map.put("memberPhone","13888888888");
        if (map != null){
            responseData.setCode(200);
            responseData.setMsg("查询成功");
            responseData.setData(map);
        }else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/addWinUser",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "添加中奖用户",notes = "添加中奖用户",httpMethod = "POST")
    public ResponseData addWinUser(Integer memberId, Integer orderId){

        if (memberId > 0 && orderId > 0){
            responseData.setCode(200);
            responseData.setMsg("添加成功");
//            responseData.setData(map);
        }else {
            responseData.setCode(500);
            responseData.setMsg("添加失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/updateLudr",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "修改幸运抽奖信息",notes = "修改幸运抽奖信息",httpMethod = "POST")
    public ResponseData updateLudr(Integer ludrId){

        if (ludrId > 0){
            responseData.setCode(200);
            responseData.setMsg("修改成功");
        }else {
            responseData.setCode(500);
            responseData.setMsg("修改失败");
        }
        return responseData;
    }
}
